package com.sense.utils
{
	public class BitmapUtils
	{
		public function BitmapUtils()
		{
		}
		
		public static function scaleBest(target:Object, scaleWidth:Number, scaleHeight:Number):void
		{
			//trace("scaleBest:",scaleWidth,scaleHeight);
			if (target.width >= target.height) 
			{
				//trace("width >= height");
				// image is wider then high,
				// match width with height
				target.width *= (scaleHeight/target.height);
				target.height = scaleHeight;
			}
			else
			{
				//trace("width < height");
				// image is higher then wide
				// match height with width
				target.height *= (scaleWidth/target.width);
				target.width = scaleWidth;
			}
			
			// redo bij te klein
			if (target.height < scaleHeight) 
			{
				//trace("heigth < scaleHeight");
				target.width *= (scaleHeight/target.height);
				target.height = scaleHeight;
			}
			if (target.width < scaleWidth) 
			{
				//trace("width < scaleWidth");
				target.height *= (scaleWidth/target.width);
				target.width = scaleWidth;
			}			
		}

	}
}